package cn.IT.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.IT.dao.ITopicDAO;
import cn.IT.dao.IUserDAO;
import cn.IT.domain.Topic;
import cn.IT.domain.User;

@Repository
@SuppressWarnings("all")
public class TopicDAO extends BaseDAO<Topic> implements ITopicDAO{
	

	@Override
	public List<Topic> findByTitle(String searchContent) {
		List<Topic> list = find("from Topic t where t.title like '%"+searchContent+"%'");
		if(!list.isEmpty()){
			return list;
		}
		return null;
	}
	
	@Override
	public List<Topic> findByType(String searchContent) {
		List<Topic> list = find("from Topic t where t.type.typeName like '%"+searchContent+"%'");
		if(!list.isEmpty()){
			return list;
		}
		return null;
	}
	
	@Override
	public Topic isTitleExist(Topic topic) {
		List<Topic> list = find("from Topic t where t.title='"+topic.getTitle()+"'");
		if(!list.isEmpty()){
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<Topic> findByUser(User u) {
		List<Topic> list = find("from Topic t where t.userByUserId.userId='"+u.getUserId()+"'");
		System.out.println(list.size());
		if(!list.isEmpty()){
			return list;
		}
		return null;
	}
	
	@Override
	public List<Topic> findNewsByToUser(User u) {
		List<Topic> list = find("from Topic t where t.userByToUserId.userId='"+u.getUserId() + "'" );
		System.out.println(list.size());
		if(!list.isEmpty()){
			return list;
		}
		return null;
	}
	
}
